const mongo = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";


function insert(collection,query){
    mongo.connect(url,function(err,db){
        if(err)throw err ;
        var dbo = db.db("mongo");
        var myobj = query;
        dbo.collection(collection).insertOne(myobj, function(err, res) {
            if (err) throw err;
            console.log("文档插入成功");
            db.close();
        });
    })
}
module.exports = insert